//
//  YZMSuggestionService.m
//  YZMicroStock
//
//  Created by wangminhong on 16/4/11.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMSuggestionService.h"
#import "YZClient.h"
#import <NSArray+LinqExtensions.h>

NSString *const sYZMSuggestionListDidUpdateNotification = @"YZMSuggestionListDidUpdateNotification";

@implementation YZMSuggestionService

+ (instancetype)sharedService
{
    static YZMSuggestionService *sInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sInstance = [[self alloc] init];
    });
    
    return sInstance;
}

- (instancetype)init{
    
    self = [super init];
    if (self) {
        
        [self fetchSuggestionTypeListSuccess:nil failure:nil];
    }
    return self;
}

- (void)fetchSuggestionTypeListSuccess:(void (^)())sucess failure: (void (^)(NSError *error))failure{
    [YZClient fetchSuggestionTypeSuccess:^(NSURLResponse *response, id responseObject) {
        
        YZGeneralResultModel *topModel = responseObject;
        if (topModel.success) {
            
            self.typeList = topModel.data;
            if (sucess) {
                sucess();
            }
        }
        else
        {
            if (failure) {
                
                failure([NSError yz_errorWithBadResponse]);
            }
        }
        
    } failure:^(NSError *error){
        
        if (failure) {
            
            failure(error);
        }
    }];
}


@end
